package cn.thoughtworks.school.usercenter.services;

import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

@Service
@Profile("test")
public class FlywayService {

    @Value("${database.url}")
    private String dbUrl;

    @Value("${database.username}")
    private String dbUser;

    @Value("${database.password}")
    private String dbPassword;

    @Value("${flyway.locations}")
    private String dbLocations;

    public void migrateDatabase() throws Exception {
        Flyway flyway = new Flyway();
        flyway.setDataSource(dbUrl, dbUser, dbPassword);
        flyway.setLocations(dbLocations);
        flyway.clean();
        flyway.migrate();
    }
}